/* sodw.t SALES ORDER LINE WRITE TRIGGER                                      */
/*Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                         */
/*All rights reserved worldwide.  This is an unpublished work.                */
/* $Revision: 1.6 $                                                           */
/*V8:ConvertMode=NoConvert                                                    */
/******************************************************************************/
/*  !Description : sod_det WRITE trigger program                              */
/*          : In order to enhance this trigger to support additional          */
/*          : interfaces, add a DO-END block similar to the one               */
/*          : used for the Warehousing Interface to (1) check for the         */
/*          : need to continue processing; (2) move the relevant              */
/*          : fields to an appropriate work area; and (3) call                */
/*          : one or more subprograms to continue processing.                 */
/*          : This .t program should remain short, relying on                 */
/*          : subprograms to perform most of the work.                        */
/******************************************************************************/
/*                             MODIFY LOG                                     */
/******************************************************************************/
/*Revision 8.5          Last Modified:  03/14/96    BY: BHolmes *J0FY*        */
/*Revision 8.5          Last Modified:  06/25/96    BY: BHolmes *J0M9*        */
/*Revision 8.5          Last Modified:  07/19/96    BY: fwy     *J0MB*        */
/*Revision 8.5          Last Modified:  07/27/96    BY: fwy     *J12B*        */
/*Revision 8.5          Last Modified:  01/07/97    BY: jpm     *J1DM*        */
/*Revision 9.1          Last Modified:  08/12/00    BY: *N0KN* Mark Brown     */
/* Revision: 1.4        BY: Jean Miller          DATE: 06/13/02  ECO: *P082*  */
/* Revision: 1.5        BY: Jean Miller          DATE: 08/01/02  ECO: *P0CL*  */
/* $Revision: 1.6 $     BY: Jean Miller          DATE: 08/17/02  ECO: *P0FN*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

TRIGGER PROCEDURE FOR WRITE OF SOD_DET OLD BUFFER OLD_SOD_DET.

{mfdeclre.i }

define new shared work-table wf_old_sod_det like sod_det.
define new shared variable w-recid as recid.

define variable w-file as character format "x(24)".
define new shared variable w-site-loc-id like whl_mstr.whl_src_dest_id.

define variable l-qualifier as character format "x(8)".

/* Warehousing Interface processing */
WI:
do:

   /* If there is no active external warehouse that is flagged to
      receive sales order export transactions, then do not process */
   if not can-find(first whl_mstr no-lock
                   where whl_mstr.whl_act and whl_mstr.whl_so_exp)
   then leave WI.

   /* Do not process if multi-DB and in central database */
   find si_mstr no-lock where si_site = sod_det.sod_site no-error.
   if global_db <> "" and si_mstr.si_db <> global_db then leave WI.

   /* If no pertinent fields have been changed, then do not process */
   if (old_sod_det.sod_nbr      = sod_det.sod_nbr
      and old_sod_det.sod_line     = sod_det.sod_line
      and old_sod_det.sod_part     = sod_det.sod_part
      and old_sod_det.sod_custpart = sod_det.sod_custpart
      and old_sod_det.sod_desc     = sod_det.sod_desc
      and old_sod_det.sod_site     = sod_det.sod_site
      and old_sod_det.sod_loc      = sod_det.sod_loc
      and old_sod_det.sod_serial   = sod_det.sod_serial
      and old_sod_det.sod_due_date = sod_det.sod_due_date
      and old_sod_det.sod_qty_ord  = sod_det.sod_qty_ord
      and old_sod_det.sod_um       = sod_det.sod_um
      and old_sod_det.sod_um_conv  = sod_det.sod_um_conv
      and old_sod_det.sod_user1    = sod_det.sod_user1
      and old_sod_det.sod_user2    = sod_det.sod_user2
      and old_sod_det.sod_cmtindx  = sod_det.sod_cmtindx)
   then leave WI.

   /* Move old sod_det values to work table for subsequent processing */
   assign
      w-recid = recid(sod_det).

   create wf_old_sod_det.
   if recid(wf_old_sod_det)= -1 then .
   assign
      wf_old_sod_det.sod_nbr       = old_sod_det.sod_nbr
      wf_old_sod_det.sod_line      = old_sod_det.sod_line
      wf_old_sod_det.sod_part      = old_sod_det.sod_part
      wf_old_sod_det.sod_custpart  = old_sod_det.sod_custpart
      wf_old_sod_det.sod_desc      = old_sod_det.sod_desc
      wf_old_sod_det.sod_site      = old_sod_det.sod_site
      wf_old_sod_det.sod_loc       = old_sod_det.sod_loc
      wf_old_sod_det.sod_serial    = old_sod_det.sod_serial
      wf_old_sod_det.sod_due_date  = old_sod_det.sod_due_date
      wf_old_sod_det.sod_qty_ord   = old_sod_det.sod_qty_ord
      wf_old_sod_det.sod_um        = old_sod_det.sod_um
      wf_old_sod_det.sod_um_conv   = old_sod_det.sod_um_conv
      wf_old_sod_det.sod_user1     = old_sod_det.sod_user1
      wf_old_sod_det.sod_user2     = old_sod_det.sod_user2
      wf_old_sod_det.sod_cmtindx   = old_sod_det.sod_cmtindx.

   /* If the order quantity is being changed from - to +,
      then create a delete transaction first */
   if wf_old_sod_det.sod_qty_ord < 0
      and sod_det.sod_qty_ord >= 0
   then do:
      w-file = "wisodd.p".
      {gprunmo.i &module="WI"
         &program="wisodd.p"}
   end.

   /* If the line being added/changed has a negative quantity ordered,
      then create an add/change transaction */
   if sod_det.sod_qty_ord < 0
   then do:
      w-file = "wisodw2.p".
      {gprunmo.i &module="WI"
         &program="wisodw2.p"}
      leave WI.
   end.

   /* If the line being added/changed has a positive quantity ordered,
      then create an add/change transaction if there is a picked quantity */
   if sod_det.sod_qty_ord >= 0
   then do:
      w-file = "wisodw.p".
      {gprunmo.i &module="WI"
         &program="wisodw.p"}
   end.

end. /* WI */

/* Track Capacity Units */
if new sod_det and
  (old_sod_det.sod_nbr  <> sod_det.sod_nbr  or
   old_sod_det.sod_line <> sod_det.sod_line)
then do:

   l-qualifier = "".

   /* See if this is from SSM/PRM */
   if sod_det.sod_fsm_type <> "" then
      l-qualifier = sod_det.sod_fsm_type.

   /* Check if Scheduled Order Line */
   else
   if sod_det.sod_sched then
      l-qualifier = "SCHED".

   {lvucap.i &TABLE="sod_det" &QUALIFIER="l-qualifier"}

end.
